#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <string.h>
#include <mysql/mysql.h>  //mysql的客户端头文件


int main()
{
    //1. 初始化MYSQL结构体
    MYSQL conn;
    MYSQL * pconn = mysql_init(&conn);
    printf("&conn: %p, pconn:%p\n\n", &conn, pconn);
    //2. 连接数据库
    const char * host = "localhost";
    const char * user = "root";
    const char * passwd = "1234";
    const char * db = "3th";
    pconn = mysql_real_connect(&conn, host, user, passwd,db, 0, NULL, 0);
    if(!pconn) {
        fprintf(stderr, "%s\n", mysql_error(&conn));
        return EXIT_FAILURE;
    }

    //3. 执行查询
    const char * sql = "Delete from student where id=9";
    int ret = mysql_real_query(pconn, sql, strlen(sql));
    if(ret != 0) {
        fprintf(stderr, "ERROR %d : %s\n", 
                mysql_errno(pconn),
                mysql_error(pconn));
        return EXIT_FAILURE;
    }

    //4. 写操作成功的情况
    printf("QUERY OK, %ld row affected.\n", mysql_affected_rows(pconn));

    //5. 关闭连接
    mysql_close(pconn);
    return 0;
}

